<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>用户添加</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/css/user.css" media="all" />
	<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
	<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1041315_0zq2yro0cfn.css">
	<style type="text/css">
		.layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
		@media(max-width:1240px){
			.layui-form-item .layui-inline{ width:100%; float:none; }
		}
		.layui-form-item .role-box {
			position: relative;
		}
		.layui-form-item .role-box .jq-role-inline {
			height: 100%;
			overflow: auto;
		}

	</style>
</head>
<body class="childrenBody">
<div class="layui-form" style="width:80%;">
	<div class="user_left">
	<div class="layui-form-item">
		<label class="layui-form-label">登录名</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="userName" lay-verify="required" placeholder="请输入登录名">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="realName" placeholder="请输入昵称">
			</div>
		</div>
		<div class="layui-form-item" pane="">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block" lay-filter="selFilter">
				<select name="sex" lay-verify="required" id="sex"  >
					<option value="">请选择性别</option>
					<option value="男">男</option>
					<option value="女">女</option>
					<option value="保密">保密</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">年龄</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="age"  placeholder="请输入年龄">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">手机</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="phone"  lay-verify="phone" placeholder="请输入邮箱">
			</div>
		</div>

		<div class="layui-inline">
			<label class="layui-form-label">生日</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="birthday" id="birthday" placeholder="请选择生日" >
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="email" lay-verify="email" placeholder="请输入邮箱">
			</div>
		</div>

	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">用户角色</label>
		<div class="layui-input-block role-box">
			<div class="jq-role-inline">
				<fieldset class="layui-elem-field">
					<legend>选择角色</legend>
					<div class="layui-field-box" th:if="${roleList!=''}">
						<input type="checkbox" name="roles" th:each="role:${roleList}" th:value="${role.id}"
							   th:text="${role.roleName}" lay-filter="role" />
		</div>
		</fieldset>
	</div>
	</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">是否启用</label>
		<div class="layui-input-block">
			<input type="checkbox" name="locked" lay-skin="switch"  lay-filter="locked"  lay-text="启用|锁定" checked>
		</div>
	</div>
</div>
	<div class="layui-col-md3 layui-col-xs12 user_right">
		<input type="hidden"  name="image"   >
		<div class="layui-upload-list">
			<img    src="/img/Starry.jpg"class="layui-circle"  alt="图片"  id="userFace">
		</div>
		<button type="button" class="layui-btn layui-btn-primary userFaceBtn" id="userFaceBtn"><i class="layui-icon">&#xe67c;</i>掐请选择头像</button>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="addUser"><i class="iconfont icon-fabu"></i>提交</button>
			<button type="reset" class="layui-btn layui-btn-normal"  id="close"><i class="iconfont icon-quxiao"></i>取消</button>
		</div>
	</div>
</form>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/common/address.js"></script>
<script type="text/javascript" src="/js/user/user.js"></script>
<script>
    layui.config({
        base: '/js/common/' //假设这是你存放拓展模块的根目录
    }).use(['form','jquery','layer','common'],function(){
        var form = layui.form,
            $    = layui.jquery,
            layer = layui.layer,
            common = layui.common;

        form.on("submit(addUser)",function(data){
            var r=document.getElementsByName("roles");
            var role=[];
            for(var i=0;i<r.length;i++){
                if(r[i].checked){
                    console.info(r[i].value);
                    role.push(r[i].value);
                }
            }
            data.field.roles = role;
            //判断用户是否启用
            if(undefined !== data.field.locked && null != data.field.locked){
                data.field.locked = 0;
            }else{
                data.field.locked = 1;
            }
            var userSaveLoading = top.layer.msg('数据提交中，请稍候',{icon: 16,time:500,shade:0.8});

            $.post("add",data.field,function (res) {
                top.layer.close(userSaveLoading);
                if(res.success){
                    common.cmsLaySucMsg(res.message);
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭                        //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.close(userSaveLoading);
                    common.cmsLayErrorMsg(res.message);
                    parent.layer.close(index); //再执行关闭
                }

            });
            return false;
        });
        $('#close').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    });
</script>
</body>
</html>